import 'package:flutter/foundation.dart';

class JrLogger {

  // A list to store log messages, if needed.
  static final List<String> _logs = [];

  /// Prints a info level log message.
  /// [msg] is the log message, and [module] specifies the module where the log is from.
  static void i(String msg, {String tag = ''}) {
    _log('[I]$msg', tag: tag);
  }

  /// Prints a debug level log message.
  /// [msg] is the log message, and [module] specifies the module where the log is from.
  static void d(dynamic msg, {String tag = ''}) {
    _log('[D]$msg', tag: tag);
  }

  /// Prints a warning level log message.
  static void w(dynamic msg, {String tag = ''}) {
    _log('[W]$msg', tag: tag);
  }

  /// Prints an error level log message.
  static void e(dynamic msg, {String tag = ''}) {
    _log('[E]$msg', tag: tag);
  }

  /// Internal method to print a log message with an optional tag name and record it.
  static void _log(String msg, {String tag = ''}) {
    final txt = '[${DateTime.now()}][$tag] $msg';
    if (kDebugMode) {
      print(txt);
      // Optionally, add the log message to the list of logs.
      _logs.add(txt);
      // Trim the log list if it exceeds a certain size.
      _trimLogs();
    }
  }

  /// Optionally, trims the list of logs to manage memory usage.
  static void _trimLogs() {
    if (_logs.length > 5000) {
      _logs.removeRange(0, 3000);
    }
  }
}
